home *** CD-ROM | disk | FTP | other *** search
- Program RestoreScrap;
- {
- This module produces a HyperCard XCMD resource to restore the
- current contents of the Clipboard from a resource with the given
- type and ID in the current stack. Call it from HyperCard as
- follows:
-
- restoreScrap resType, resID
-
- Written by Lawrence D'Oliveiro 1988 January 13.
- Last modified 1988 July 13.
- }
- {$C 'XCMD' 129 'RestoreScrap' 32}
- {$H 'XCmdHeader'}
- {$T 'XCMD'}
-
- Uses
- MacIntf,
- HyperXCmd;
-
- Procedure TheProc
- (
- ParamPtr : XCmdPtr
- );
- { actual code for the XCMD. }
-
- Var
- TheResType : ResType;
- TheResID : Integer;
- TheResource : Handle;
- TheResourceLength : LongInt;
- Err : OSErr;
-
- Procedure GetScrapResource;
- { gets the resource containing the scrap. }
-
- Procedure GetResTypeAndID;
- { get resource type and ID. }
-
- Var
- ResIDString : Str255;
-
- Begin
- BlockMove(ParamPtr^.Params[1]^, @TheResType, 4);
- ZeroToPas(ParamPtr, ParamPtr^.Params[2]^, ResIDString);
- TheResID := StrToNum(ParamPtr, ResIDString)
- End {GetResTypeAndID};
-
- Begin {GetScrapResource}
- GetResTypeAndID;
- TheResource := GetResource(TheResType, TheResID)
- End {GetScrapResource};
-
- Procedure RestoreTheScrap;
- { actually restore the scrap from TheResource. }
-
- Type
- TypePtr = ^OSType;
- SizePtr = ^LongInt;
-
- Var
- ScrapPtr, ScrapOffset : LongInt;
- ThisType : OSType;
- ThisSize : LongInt;
- Done : Boolean;
-
- Begin
- HNoPurge(TheResource);
- ScrapOffset := 0;
- Err := ZeroScrap;
- Done := Err <> NoErr;
- While not Done do
- Begin
- If ScrapOffset > TheResourceLength - 8 then
- Done := True;
- If not Done then
- Begin
- HLock(TheResource);
- ScrapPtr := Ord4(TheResource^);
- ThisType := TypePtr(ScrapPtr + ScrapOffset)^;
- ThisSize := SizePtr(ScrapPtr + ScrapOffset + 4)^;
- Err := PutScrap(ThisSize, ThisType, Ptr(ScrapPtr + ScrapOffset + 8));
- HUnlock(TheResource);
- If Err <> NoErr then
- Done := True
- End {If};
- If not Done then
- ScrapOffset := ScrapOffset + ThisSize + 8 + Ord(Odd(ThisSize))
- End {While};
- HPurge(TheResource)
- End {RestoreTheScrap};
-
- Procedure ReturnError
- (
- Error : Integer
- );
- { return error code as a string. }
-
- Var
- ErrorString : Str255;
-
- Begin
- NumToString(Error, ErrorString);
- ParamPtr^.ReturnValue := PasToZero(ParamPtr, ErrorString)
- End {ReturnError};
-
- Begin {TheProc}
- GetScrapResource;
- If TheResource <> Nil then
- Begin
- TheResourceLength := GetHandleSize(TheResource);
- RestoreTheScrap;
- If SystemEdit(3 {Copy}) then { so MultiFinder notices that scrap has changed }
- { whoopee };
- If Err <> NoErr then
- ReturnError(Err)
- End
- else
- ReturnError(resNotFound)
- End {TheProc};
-
- Begin {RestoreScrap}
- { dummy mainline }
- End {RestoreScrap}.
-